<!DOCTYPE html>
<script src="full-screen-test.js"></script>
<p>Test that webkitCancelFullScreen only exits one level of fullscreen</p>
<div><span></span></div>
<script>
    var callback;
    function fullscreenChanged(event)
    {
        if (callback)
            callback(event)
    };
    waitForEvent(document, "webkitfullscreenchange", fullscreenChanged);

    var div = document.querySelector("div");
    function divEnteredFullScreen()
    {
        testExpected("document.webkitCurrentFullScreenElement", div);
        callback = spanEnteredFullScreen;
        runWithKeyDown(function() { span.webkitRequestFullScreen(); });
    };

    var span = document.querySelector("span");
    function spanEnteredFullScreen()
    {
        testExpected("document.webkitCurrentFullScreenElement", span);
        callback = cancelledFullScreen;
        document.webkitCancelFullScreen();
    };

    function cancelledFullScreen()
    {
        testExpected("document.webkitCurrentFullScreenElement", div);
        endTest();
    };

    callback = divEnteredFullScreen;
    runWithKeyDown(function() { div.webkitRequestFullScreen(); });
</script>
